package com.modouyu.novel.config;

import com.modouyu.novel.core.freemark.ArticleList;
import com.modouyu.novel.core.freemark.ChannelList;
import freemarker.template.Configuration;
import freemarker.template.TemplateModelException;
import org.springframework.beans.factory.annotation.Autowired;

import javax.annotation.PostConstruct;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by Administrator on 2018/5/7.
 */
@org.springframework.context.annotation.Configuration
public class FreemarkerConfig {



    @Autowired
    private Configuration configuration;

    @Autowired
    private ChannelList channelList;
    @Autowired
    private ArticleList articleList;




    @PostConstruct
    public void setSharedVariable() throws TemplateModelException {
        configuration.setSharedVaribles(getSharedVaribles());
    }


    public Map<String, Object> getSharedVaribles() {
        Map<String, Object> sharedVaribles = new HashMap<>();
        sharedVaribles.put("_channel_list", channelList);
        sharedVaribles.put("_article_list", articleList);
        return sharedVaribles;
    }





}
